/**
 * 库房保存后刷新树
 * @Bind #updateActionSaveWarehouse.onSuccess
 */
!function(self, arg) {
	//view.id("dsWarehouseTree").clear();
	//view.id("dsWarehouseTree").flush();
	view.id("dsWarehouseTree").flushAsync();
	//view.id("whouseTree").refresh();
}

//@Bind #warebinAddButton.onClick
!function(self, arg) {
var dsWarebin = view.id('dsWarebin');
//添加数据
	dsWarebin.insert({
		warehouseUid:mWarehouseUid,
	});
}
//@Bind #warebinDeleteButton.onClick
!function(self, arg) {
var dswarebin = view.id('dsWarebin');
dorado.MessageBox.confirm('是否删除?',function(){
dswarebin.getData('#').remove();
});
}


//@Bind #warehouseKeeperAddButton.onClick
!function(self, arg, dsWarehouse) {
	var dsWarehouseKeeper = view.id('dsWarehouseKeeper');
	var warehouse = dsWarehouse.getData("#");
	//添加数据
	var warehouseKeeper = dsWarehouseKeeper.insert();
	warehouseKeeper.set("warehouseUid", mWarehouseUid);
	warehouseKeeper.set("warehouse.warehouseId", warehouse.get("warehouseId"));
	
}

//@Bind #warehouseKeeperButton.onClick
!function(self, arg) {
	var dswarebin = view.id('dsWarehouseKeeper');
	dorado.MessageBox.confirm('是否删除?',function(){
	dswarebin.getData('#').remove();
	});
	}

//@Bind #warehouseAddButton.onClick
!function(self, arg) {
	var dsWarehouse = view.id("dsWarehouse");
	//view.id('ajaxActiongetUniqueId').execute(function(result){
	//添加数据
	dsWarehouse.insert({
		warehouseUid:warehouseUid,
	});
	//});
	}

//@Bind #warehouseDeleteButton.onClick
!function(self, arg) {
	var dsWarehouse = view.id('dsWarehouse');
	dorado.MessageBox.confirm('是否删除?',function(){
	view.id('ajaxActionWarehouse').set('parameter',mWarehouseUid).execute(function(result){
		if(result == true){
			dsWarehouse.getData('#').remove();
		}else{
			dorado.MessageBox.alert('库房已定义,不能执行删除!');
		}
	});
	});
	}


//@Bind #invInfoAddButton.onClick
!function(self, arg) {
	var dsInvInfo = view.id('dsInvInfo');
	//添加数据
	dsInvInfo.insert({
		warehouseUid:mWarehouseUid,
	});
	}

//@Bind #invInfoDeleteButton.onClick
!function(self, arg) {
	var dsInvInfo = view.id('dsInvInfo');
	dorado.MessageBox.confirm('是否删除?',function(){
	dsInvInfo.getData('#').remove();
	});
	}



//@Bind #warehouseDeptAddButton.onClick
!function(self, arg) {
	var dsWarehouseDept = view.id('dsWarehouseDept');
	var dsWarehouse = view.id('dsWarehouse');
	var warehouse = dsWarehouse.getData("#");
	//添加数据
	var warehouseDept = dsWarehouseDept.insert();
	warehouseDept.set("warehouseUid", mWarehouseUid);
	warehouseDept.set("warehouse.warehouseId", warehouse.get("warehouseId"));
	warehouseDept.set("warehouse.warehouseName", warehouse.get("warehouseName"));
}



//@Bind #warehouseDeptDeleteButton.onClick
!function(self, arg) {
	var dsWarehouseDept = view.id('dsWarehouseDept');
	dorado.MessageBox.confirm('是否删除?',function(){
	dsWarehouseDept.getData('#').remove();
	});


	}



//@Bind #warebinKeeperAddButton.onClick
!function(self, arg) {
	var dsWarebinKeeper = view.id('dsWarebinKeeper');
	//添加数据
	dsWarebinKeeper.insert({
		warehouseUid: mWarehouseUid,
	});
	}

//@Bind #warebinKeeperDeleteButton.onClick
!function(self, arg) {
	var dsWarebinKeeper = view.id('dsWarebinKeeper');
	dorado.MessageBox.confirm('是否删除?',function(){
		dsWarebinKeeper.getData('#').remove();
		
	});
	}


//@Bind #dataSetDropDownBintype.beforeExecute
!function(self, arg) {
var dsTypesData = view.id("dsTypesData");
dsTypesData.set("parameter",{"typeName":"bintype"});
dsTypesData.flush();
}

// @Bind #buttonDept.onClick
!function(self,arg,autoFromDept,dsGetDept) {
var entity = autoFromDept.get("entity");
//将实体对象作为参数传入，并异步刷新
dsGetDept.set("parameter",entity).flushAsync();
}

//@Bind #buttonDepts.onClick
!function(self,arg,autoFromDepts,dsGetDeptName) {
var entity = autoFromDepts.get("entity");
//将实体对象作为参数传入，并异步刷新
dsGetDeptName.set("parameter",entity).flushAsync();
}

//@Bind #buttonDeptName.onClick
!function(self,arg,autoFromDeptName,dsDeptName) {
var entity = autoFromDeptName.get("entity");
//将实体对象作为参数传入，并异步刷新
dsDeptName.set("parameter",entity).flushAsync();
}

//@Bind #buttonWarebinName.onClick
!function(self,arg,AfWarebin,dsGetWarebinIdAndWarebinName) {
var entity = AfWarebin.get("entity");
//将实体对象作为参数传入，并异步刷新
dsGetWarebinIdAndWarebinName.set("parameter",entity).flushAsync();
}

//@Bind #buttonEmployeeName.onClick
!function(self,arg,autoFromEmployeeName,dsGetEmployeeIdAndName) {
var entity = autoFromEmployeeName.get("entity");
//将实体对象作为参数传入，并异步刷新
dsGetEmployeeIdAndName.set("parameter",entity).flushAsync();
}

//@Bind #buttonEmployeeNames.onClick
!function(self,arg,autoFromEmployeeNames,dsGetEmployees) {
var entity = autoFromEmployeeNames.get("entity");
//将实体对象作为参数传入，并异步刷新
dsGetEmployees.set("parameter",entity).flushAsync();
}

//@Bind #datagirdDeptName.onDataRowClick
!function(self, arg, dsDeptName, dsWarehouseDept) {
	var dsWarehouseDept = dsWarehouseDept.getData("#");
	var dsDeptName = dsDeptName.getData("#");
	dsWarehouseDept.set("dept.deptName", dsDeptName.get("deptName"));
	dsWarehouseDept.set("deptUid", dsDeptName.get("deptUid"));
	
	view.id('customDropDownWarehouseDepts').close();
}


//var warehouseId;

/*
 * 库存初始化下datagirdDepts表格行点击事件
 * @Bind #datagirdDepts.onDataRowClick
 */
!function(self, arg, dsGetDeptName, dsInvInfo,DropDownWarehouseDept) {
	var dsGetDeptName = dsGetDeptName.getData("#");
	var invinfo = dsInvInfo.getData("#");
	invinfo.set("dept.deptName", dsGetDeptName.get("deptName"));
	invinfo.set("deptUid", dsGetDeptName.get("deptUid"));
	DropDownWarehouseDept.close();
}

/*
 * 人员信息下employeesDataGird表格行点击事件
 * @Bind #employeesDataGird.onDataRowClick
 */ 
!function(self, arg, dsGetEmployees, dsWarehouseKeeper, dropDownGetemployee) {
	var dsGetEmployees = dsGetEmployees.getData("#");
	var dsWarehouseKeeper = dsWarehouseKeeper.getData("#");
	dsWarehouseKeeper.set("employee.employeeName", dsGetEmployees
			.get("employeeName"));
	dsWarehouseKeeper.set("employeeUid", dsGetEmployees.get("employeeUid"));
	dropDownGetemployee.close();
}

/*
 * 库房信息下datagirdDept表格行点击事件
 *@Bind #datagirdDept.onDataRowClick
 */ 
!function(self, arg, dsGetDept, dsWarehouse,
		customDropDownWarehouseDept) {
	var warehouse = dsWarehouse.getData("#");
	var dept = dsGetDept.getData("#");
	//console.log(warehouse.get("dept"));
	//console.log(dept.get("deptName"));
	//warehouse.get("dept").set("deptName",dept.get("deptName"));
	warehouse.set("dept.deptName", dept.get("deptName"));
	warehouse.set("deptUid", dept.get("deptUid"));
	//刷新数据
	view.id('formEleDeptName').refreshData();
	customDropDownWarehouseDept.close();
}

/*
 * 库房部门关系下dept1表格行点击事件
 *@Bind #dept1.onDataRowClick
 */ 
!function(self, arg, dsGetDepts, dsWarehouseDept, warehouseDept1) {
	var dsGetDepts = dsGetDepts.getData("#");
	var dsWarehouseDept = dsWarehouseDept.getData("#");
	dsWarehouseDept.set("dept.deptName", dsGetDepts.get("deptName"));
	dsWarehouseDept.set("deptUid", dsGetDepts.get("deptUid"));
	warehouseDept1.close();
}

/*
 * 库房部门关系下dept2表格行点击事件
 *@Bind #dept2.onDataRowClick
 */ 
!function(self, arg, dsGettypesData, dsWarehouseDept, warehouseDept2) {
	var dsGettypesData = dsGettypesData.getData("#");
	var dsWarehouseDept = dsWarehouseDept.getData("#");
	dsWarehouseDept.set("businessType", dsGettypesData.get("idDescription"));
	warehouseDept2.close();
}

/*
 * 库房部门关系下dept3表格行点击事件
 *@Bind #dept3.onDataRowClick
 */ 
!function(self, arg, dsGetWarehouse, dsWarehouseDept, warehouseDept3) {
	var WarehouseDept = dsWarehouseDept.getData("#");
	var GetWarehouse = dsGetWarehouse.getData("#");
	WarehouseDept.set("warehouse.warehouseName", GetWarehouse
			.get("warehouseName"));
	warehouseDept3.close();
}

/*
 * 柜位人员关系下datagirdWarebin表格行点击事件
 *@Bind #datagirdWarebin.onDataRowClick
 */ 
!function(self, arg, dsGetWarebinIdAndWarebinName, dsWarebinKeeper,
		customDropDownGetWarebinName) {
	var dsGetWarebinIdAndWarebinName = dsGetWarebinIdAndWarebinName
			.getData("#");
	var dsWarebinKeeper = dsWarebinKeeper.getData("#");
	dsWarebinKeeper.set("warebin.binName", dsGetWarebinIdAndWarebinName
			.get("binName"));
	dsWarebinKeeper.set("warebinUid",dsGetWarebinIdAndWarebinName.get("warebinUid"));
	//dsWarebinKeeper.set("warehouseUid",mWarehouseUid);
	customDropDownGetWarebinName.close();
}

/*
 * 柜位人员关系下employeeDataGird表格行点击事件
 *@Bind #employeeDataGird.onDataRowClick
 */ 
!function(self, arg, dsGetEmployeeIdAndName, dsWarebinKeeper,
		customDropDownGetemployeeName) {
	var dsGetEmployeeIdAndName = dsGetEmployeeIdAndName.getData("#");
	var dsWarebinKeeper = dsWarebinKeeper.getData("#");
	dsWarebinKeeper.set("employee.employeeName", dsGetEmployeeIdAndName.get("employeeName"));
	dsWarebinKeeper.set("employeeUid", dsGetEmployeeIdAndName.get("employeeUid"));
	customDropDownGetemployeeName.close();
}

/*onCurrentChange
*@Bind #whouseTree.onCurrentChange
*/
!function(self, arg) {
	var dropDown = dorado.widget.DropDown.findDropDown(self);
	//获取当前节点
	var node = self.get("currentNode");
	//获取当前树节点对应的数据实体
	var curEntity = self.get("currentEntity");
	if (curEntity.dataType.get("name") == "dtWarehouse") {
		//获取当前树节点对应的数据实体中的warehouseId属性
		var warehouseId = curEntity.get("uuid");
		var sWarehouseUid = curEntity.get("warehouseId");
		//获取当前树节点对应的数据实体中的warehouseName属性
		var warehouseName = curEntity.get("warehouseName");
		//定义公共变量
		warehouseUid = sWarehouseUid;
		mWarehouseUid = warehouseId;
		mWarehouseName = warehouseName;
			// 柜位注册
			var dsWarebin = view.id("dsWarebin");
			dsWarebin.set("parameter", {
				"warehouseUid" : warehouseId
			});
			dsWarebin.flush();
		
			// 人员信息
			var dsWarehouseKeeper = view.id("dsWarehouseKeeper");
			dsWarehouseKeeper.set("parameter", {
				"warehouseUid" : warehouseId
			});
			dsWarehouseKeeper.flush();
			
			// 库房信息
			var dsWarehouse = view.id("dsWarehouse");
			dsWarehouse.set("parameter",{
				"warehouseUid" : warehouseId
			});
			dsWarehouse.flush();
			
			// 库存初始化
			var dsivInfo = view.id("dsInvInfo");
			dsivInfo.set("parameter", {
				"warehouseUid" : warehouseId
			});
			dsivInfo.flush();	
			
			// 库房部门
			var dsWarehouseDept = view.id("dsWarehouseDept");
			dsWarehouseDept.set("parameter", {
				"warehouseUid" : warehouseId
			});
			dsWarehouseDept.flush();
		
			// 柜位信息
			var dsWarebinKeepe = view.id("dsWarebinKeeper");
			dsWarebinKeepe.set("parameter", {
				"warehouseUid" : warehouseId
			});
			dsWarebinKeepe.flush();
	}
}


// @Bind #dataSetDropDownWareType.beforeExecute
!function(self, arg, dataSetTypeData) {
	dataSetTypeData.set("parameter", {
		typeName : "bintype"
	});
	dataSetTypeData.flush();
}

/*
 * 库房初始化下invInfoDropDown下拉框dsInvInfoBatchNumAndSnDataGird表格行点击事件
 * @Bind #invInfoBatchNumAndSn.onDataRowClick
 */ 
!function(self, arg,dsInvInfoBatchNumAndSn,dsInvInfo,invInfoDropDown) {
	var dsInvInfoBatchNumAndSn = dsInvInfoBatchNumAndSn.getData("#");
	var invinfo = dsInvInfo.getData("#");
	invinfo.set("batchNum", dsInvInfoBatchNumAndSn.get("batchNum"));
	invInfoDropDown.close();
}

/*
 * 库房初始化下customDropDown1下拉框InvInfoWarebinAndpartDrawingIdDataGird表格行点击事件
 *@Bind #InvInfoWarebinAndpartDrawingIdDataGird.onDataRowClick
 */ 
!function(self, arg, dsInvInfoWarebinAndpartDrawingId, dsInvInfo,
		customDropDown1) {
	var dsInvInfoWarebinAndpartDrawingId = dsInvInfoWarebinAndpartDrawingId.getData("#");
	var invinfo = dsInvInfo.getData("#");
	invinfo.set("warebin.binName", dsInvInfoWarebinAndpartDrawingId.get("warebin.binName"));
	invinfo.set("warebinUid", dsInvInfoWarebinAndpartDrawingId.get("warebinUid"));
	customDropDown1.close();
}

/*
 * 库房信息下dpWarehouseType下拉框beforeExecute事件
 *@Bind #dpWarehouseType.beforeExecute
 */ 
!function(self,arg,dsTypesData) {
	dsTypesData.set("parameter", {typeName:"warehousetype"});
	dsTypesData.flush();
}


//@Bind #dpWarehouseType.onValueSelect
!function(self,arg,dsTypesData,dsWarehouse) {
	var dsTypesData = dsTypesData.getData("#");
	var dsWarehouse = dsWarehouse.getData("#");
	dsWarehouse.set("warehouseType", dsTypesData.get("idDescription"));
//	//刷新数据
//	view.id('formEleDeptType').refreshData ();
}


 //@Bind #dataSetDropDownWareType.onValueSelect
!function(self,arg,dsTypesData,dsWarebin) {
	var dsWarebin = view.id("dsWarebin");
	var Warebin = dsWarebin.getData("#");
	var dsTypesData = view.id("dsTypesData");
	var TypesData = dsTypesData.getData("#");
	Warebin.set("binType",TypesData.get("typeId"));
	Warebin.set("binTypeDesc",TypesData.get("idDescription"));
	
}

//@Bind #dataSetDropDownbusinessType.beforeExecute
!function(self,arg) {
	var dsTypesData = view.id("dsTypesData");
	dsTypesData.set("parameter", {typeName : "business_type"});
	dsTypesData.flush();
}

////@Bind #dsRoot.onReady
//!function(self, arg) {
//	self.insert({
//		warehouseName : "库房列表"
//	});
//
//}
//@Bind #dpDept.beforeExecute
!function(self, arg, dsTreeDept) {
	view.id("ajaxActionDeptId").execute(function(result){
		dsTreeDept.set("parameter", result).flush();
		
	});
}

//@Bind #deptTree.onDataRowClick
!function(self, arg, dsWarehouse) {
	var warehouse = dsWarehouse.getData("#");
	var curEntity = self.get("currentEntity");
	
	warehouse.set("deptUid", curEntity.get("uuid"));
	warehouse.set("dept.deptName", curEntity.get("deptName"));
	dorado.widget.DropDown.findDropDown(self).close();
	
}
